package com.jmx.mstcodesandbox.controller;

import com.jmx.mstcodesandbox.CodeSandBox;
import com.jmx.mstcodesandbox.javasandbox.JavaDockerCodeSandBox;
import com.jmx.mstcodesandbox.model.ExecuteCodeRequest;
import com.jmx.mstcodesandbox.model.ExecuteCodeResponse;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class CodeSandBoxController {
    @Resource(name = "docker")
    private CodeSandBox codeSandBox;
    @PostMapping("/executeCode")
    public ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRequest){
        System.out.println("executeCodeRequest = " + executeCodeRequest);
        ExecuteCodeResponse executeCodeResponse = codeSandBox.executeCode(executeCodeRequest);
        if (executeCodeResponse == null) {
            throw new RuntimeException("响应结果为空");
        }
        System.out.println("executeCodeResponse = " + executeCodeResponse);
        return executeCodeResponse;
    }
}
